package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年09月09日 9:39
 */
@RestController
public class DataController {
    @Autowired
    private DataService dataService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");

        List<Map<String,Object>>maps=dataService.select1();
        Map<String, Object> map = maps.get(0);
        retult.put("data",map.get("cta"));
        return retult;
    }
    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONArray data = new JSONArray();
        retult.put("data",data);

        JSONObject col1 = new JSONObject();
        col1.put("name","货物名称");
        col1.put("cta","cta");
        data.add(col1);

        List<Map<String,Object>>maps=dataService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            data.add(row);
        }
        return retult;
    }
    @RequestMapping("/s3")
    public  JSONObject select3(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows=new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","各机构名称");
        col1.put("id","name");
        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","运输次数");
        col2.put("id","cta");
        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","运输排名");
        col3.put("id","ctb");
        columns.add(col3);


        List<Map<String,Object>>maps=dataService.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            rows.add(row);
        }

        return retult;
    }
    @RequestMapping("/s4")
    public  JSONObject select4(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray mapData = new JSONArray();
        data.put("mapData",mapData);

        JSONObject col1 = new JSONObject();
        col1.put("name","省份");
        col1.put("valueName","name");
        mapData.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","运单数量");
        col2.put("sizeValueName","cta");
        mapData.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","运单金额");
        col3.put("typeName","ctb");
        mapData.add(col3);

        List<Map<String,Object>>maps=dataService.select4();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("valueName",map.get("name"));
            row.put("sizeValue",map.get("cta"));
            row.put("type",map.get("ctb"));
            mapData.add(row);
        }
        return  retult;
    }
}
